/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipass;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Brothers
 */
public class PassForSeason extends SkiPass {

    private static final long MILLDAY = 86400000;
    private int numberDay;

    //public PassForSeason() {;}
    public PassForSeason(int idPass, Enums.PassType typePass,
            Calendar firstDatePass, Enums.Week ogrPass) {
        super(idPass, typePass, firstDatePass, ogrPass);
        this.numberDay = -1;
    }

    @Override
    public boolean isValidDate(Calendar date) {
        Date temp;
        Date tempFirst;
        temp = date.getTime();
        tempFirst = this.getFirstDate().getTime();
        long mill = temp.getTime();
        long millFirst = tempFirst.getTime();
        return mill - millFirst >= this.numberDay * MILLDAY;
    }

    @Override
    public void setNumberDay(int day) {
        this.numberDay = Enums.SeasonEnum.values()[day].getEnum();
    }

    public int getNumberDay() {
        return this.numberDay;
    }

    public boolean isPassForSeasonRight(AccountingSystem sys, int id) {

        if (!this.isValidDate(sys.getDate())) {
            this.blockPass();
            ((Turnstile) sys.getTurn().get(id)).plusAccessFalse();
            return false;
        } else {
            return true;
        }
    }
}
